<template>
  <div class="list-table">
    <!-- <div class="area-header">
      <span class="area-header-title">{{ $t('关键字数据集字段列') }}</span>
    </div> -->
    <!-- <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form> -->

    <el-table v-loading="loading" :data="wordOnlineKeyWordListList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('指标名称')" align="center" prop="keyWord" min-width="180" />
      <el-table-column :label="$t('指标标识')" align="center" prop="keyCode" min-width="180" />
      <el-table-column :label="$t('数据类型')" align="center" prop="dataType" :formatter="formatDateTypeColumn" min-width="50" />
      <el-table-column :label="$t('字段名称')" align="center" prop="label" />
      <el-table-column :label="$t('字段别名')" align="center" prop="fieldAlias" />
      <el-table-column :label="$t('字段长度')" align="center" prop="fieldLength" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listWordOnlineKeyWordList } from '@/api/system/word/wordOnlineKeyWordList'
export default {
    components: {
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 关键字数据集字段列表格数据
          wordOnlineKeyWordListList: [],
          // 弹出层标题
          title: '关键字数据集字段列',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              parentId: undefined,
              label: undefined,
              type: undefined,
              format: undefined,
              coordinates: undefined,
              sort: undefined,
              fieldAlias: undefined,
              fieldLength: undefined,
              fieldName: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {},
          dateTypeOptions: []
      }
  },
  created() {
      // this.getList()
      this.getDicts('key_data_type').then((response) => {
        this.dateTypeOptions = response.data
      })
  },
  methods: {
    init(data) {
      if (data && data.fieldName) {
         this.queryParams.label = data.fieldName
         this.getList()
      }
    },
    /** 查询关键字数据集字段列列表 */
    getList() {
        this.loading = true
        listWordOnlineKeyWordList(this.queryParams).then(response => {
            this.wordOnlineKeyWordListList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            parentId: undefined,
            label: undefined,
            type: undefined,
            format: undefined,
            coordinates: undefined,
            sort: undefined,
            fieldAlias: undefined,
            fieldLength: undefined,
            fieldName: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.wordOnlineKeyWordListForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.wordOnlineKeyWordListForm.init(row)
        })
    },
    formatDateTypeColumn(row) {
      return this.selectDictLabel(this.dateTypeOptions, row.dataType)
    }
  }
}
</script>
